package com.zlict.admin.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.zlict.common.annotation.Log;
import com.zlict.common.core.controller.BaseController;
import com.zlict.common.core.domain.AjaxResult;
import com.zlict.common.enums.BusinessType;
import com.zlict.admin.domain.RdVoucher;
import com.zlict.admin.service.IRdVoucherService;
import com.zlict.common.utils.poi.ExcelUtil;
import com.zlict.common.core.page.TableDataInfo;

/**
 * 物料领用-单据Controller
 * 
 * @author ruoyi
 * @date 2025-06-18
 */
@RestController
@RequestMapping("/system/voucher")
public class RdVoucherController extends BaseController
{
    @Autowired
    private IRdVoucherService rdVoucherService;

    /**
     * 查询物料领用-单据列表（包含材料信息）
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:list')")
    @GetMapping("/list")
    public TableDataInfo list(RdVoucher rdVoucher)
    {
        startPage();
        List<RdVoucher> list = rdVoucherService.selectRdVoucherList(rdVoucher);
        return getDataTable(list);
    }

    /**
     * 导出物料领用-单据列表
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:export')")
    @Log(title = "物料领用-单据", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RdVoucher rdVoucher)
    {
        List<RdVoucher> list = rdVoucherService.selectRdVoucherList(rdVoucher);
        ExcelUtil<RdVoucher> util = new ExcelUtil<RdVoucher>(RdVoucher.class);
        util.exportExcel(response, list, "物料领用-单据数据");
    }

    /**
     * 获取物料领用-单据详细信息（包含材料信息）
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(rdVoucherService.selectRdVoucherById(id));
    }

    /**
     * 新增物料领用-单据（包含材料信息）
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:add')")
    @Log(title = "物料领用-单据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RdVoucher rdVoucher)
    {
        int result = rdVoucherService.insertRdVoucher(rdVoucher);
        if (result > 0) {
            return success("新增成功，单据号：" + rdVoucher.getReceiptNumber());
        }
        return error("新增失败");
    }

    /**
     * 修改物料领用-单据（包含材料信息）
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:edit')")
    @Log(title = "物料领用-单据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RdVoucher rdVoucher)
    {
        return toAjax(rdVoucherService.updateRdVoucher(rdVoucher));
    }

    /**
     * 删除物料领用-单据（包含材料信息）
     */
    //@PreAuthorize("@ss.hasPermi('system:voucher:remove')")
    @Log(title = "物料领用-单据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(rdVoucherService.deleteRdVoucherByIds(ids));
    }
}
